﻿//*******************************************************************
// 文件名（File Name）：         
// 数据表（Tables）：         nothing
// 作者（Author）：           汲磊举
// 日期（Create Date）：      2016.1.17
//*******************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;



namespace WpfApplication1
{

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        [DllImport("User32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);
       
        public MainWindow()
        {
            InitializeComponent();
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = "calc.exe";
            Process.Start(info);
            Thread.Sleep(200);  //休眠，等待启动计算器
            IntPtr cal = FindWindow(null,"计算器");
           

            SetForegroundWindow(cal);
            Thread.Sleep(1000);  
            SendKeys.SendWait("27");
            Thread.Sleep(1000);
            SendKeys.SendWait("+");
            Thread.Sleep(1000);
            SendKeys.SendWait("13");
            Thread.Sleep(1000);
            SendKeys.SendWait("=");
            
        }
    }
}
